<template>
  <el-dialog :visible.sync="visible" width="300px" :show-close="false">
    <div class="user-info-box">
      <div class="user-avatar">
        <head-image :url="userInfo.headImage" :name="userInfo.nickName" :size="60"></head-image>
      </div>
      <div class="user-name">{{ userInfo.nickName }}</div>
      <div class="btn-group">
        <el-button type="primary" @click="onChat">发送消息</el-button>
        <el-button 
          v-if="userInfo.memberType !== 'ROBOT'" 
          type="success" 
          @click="onAddFriend"
        >加为好友</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  computed: {
    userInfo() {
      return this.$store.state.userStore.userInfoBox;
    },
    visible: {
      get() {
        return this.$store.state.userStore.showUserInfoBox;
      },
      set(value) {
        this.$store.commit("showUserInfoBox", null);
      }
    }
  },
  methods: {
    onChat() {
      // 处理发送消息
      this.$store.commit("showUserInfoBox", null);
      this.$store.commit("activeChat", {
        type: "PRIVATE",
        targetId: this.userInfo.id
      });
    },
    onAddFriend() {
      // 处理添加好友
      this.$store.commit("showUserInfoBox", null);
      this.$store.commit("showAddFriend", this.userInfo);
    }
  }
}
</script> 